{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "  return 3*x**2 - 4*x + 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(3.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7f9b98432ee0>]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAkRklEQVR4nO3dd3yV5f3/8dcnkwQCIRBmwg5hD4mIimhlSAXRWkXpF8E6UGtrbSutddTafq1YW7+ttQ6cqNRRxOLCURwIAhL2StgbQghkEMi+fn9w7I8qSNbJfcb7+XjwOOc+I/f76CNvLu5z3ddtzjlERCS0RHgdQERE6p/KXUQkBKncRURCkMpdRCQEqdxFREJQlNcBAFq2bOk6derkdQwRkaCybNmyg8655JM9FxDl3qlTJzIzM72OISISVMxsx6me02EZEZEQpHIXEQlBKncRkRCkchcRCUEqdxGREHTacjez58zsgJmtPeGxJDP7yMw2+W6bn/Dcr81ss5llm9lF/gouIiKnVp2R+wvA6K89dicwzzmXBszzbWNmvYCrgd6+9zxuZpH1llZERKrltOX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nmci5YAbRAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "xs = np.arange(-5, 5, 0.25)\n",
    "ys = f(xs)\n",
    "plt.plot(xs, ys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.999378523327323e-06"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "h = 0.000001\n",
    "x = 2/3\n",
    "(f(x + h) - f(x))/h"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.0\n"
     ]
    }
   ],
   "source": [
    "# les get more complex\n",
    "a = 2.0\n",
    "b = -3.0\n",
    "c = 10.0\n",
    "d = a*b + c\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "d1 4.0\n",
      "d2 4.0001\n",
      "slope 0.9999999999976694\n"
     ]
    }
   ],
   "source": [
    "h = 0.0001\n",
    "\n",
    "# inputs\n",
    "a = 2.0\n",
    "b = -3.0\n",
    "c = 10.0\n",
    "\n",
    "d1 = a*b + c\n",
    "c += h\n",
    "d2 = a*b + c\n",
    "\n",
    "print('d1', d1)\n",
    "print('d2', d2)\n",
    "print('slope', (d2 - d1)/h)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Value(data=-8.0)"
      ]
     },
     "execution_count": 257,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Value:\n",
    "  \n",
    "  def __init__(self, data, _children=(), _op='', label=''):\n",
    "    self.data = data\n",
    "    self.grad = 0.0\n",
    "    self._backward = lambda: None\n",
    "    self._prev = set(_children)\n",
    "    self._op = _op\n",
    "    self.label = label\n",
    "\n",
    "  def __repr__(self):\n",
    "    return f\"Value(data={self.data})\"\n",
    "  \n",
    "  def __add__(self, other):\n",
    "    out = Value(self.data + other.data, (self, other), '+')\n",
    "    \n",
    "    def _backward():\n",
    "      self.grad += 1.0 * out.grad\n",
    "      other.grad += 1.0 * out.grad\n",
    "    out._backward = _backward\n",
    "    \n",
    "    return out\n",
    "\n",
    "  def __mul__(self, other):\n",
    "    out = Value(self.data * other.data, (self, other), '*')\n",
    "    \n",
    "    def _backward():\n",
    "      self.grad += other.data * out.grad\n",
    "      other.grad += self.data * out.grad\n",
    "    out._backward = _backward\n",
    "      \n",
    "    return out\n",
    "  \n",
    "  def tanh(self):\n",
    "    x = self.data\n",
    "    t = (math.exp(2*x) - 1)/(math.exp(2*x) + 1)\n",
    "    out = Value(t, (self, ), 'tanh')\n",
    "    \n",
    "    def _backward():\n",
    "      self.grad += (1 - t**2) * out.grad\n",
    "    out._backward = _backward\n",
    "    \n",
    "    return out\n",
    "  \n",
    "  def backward(self):\n",
    "    \n",
    "    topo = []\n",
    "    visited = set()\n",
    "    def build_topo(v):\n",
    "      if v not in visited:\n",
    "        visited.add(v)\n",
    "        for child in v._prev:\n",
    "          build_topo(child)\n",
    "        topo.append(v)\n",
    "    build_topo(self)\n",
    "    \n",
    "    self.grad = 1.0\n",
    "    for node in reversed(topo):\n",
    "      node._backward()\n",
    "\n",
    "\n",
    "a = Value(2.0, label='a')\n",
    "b = Value(-3.0, label='b')\n",
    "c = Value(10.0, label='c')\n",
    "e = a*b; e.label = 'e'\n",
    "d = e + c; d.label = 'd'\n",
    "f = Value(-2.0, label='f')\n",
    "L = d * f; L.label = 'L'\n",
    "L"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "from graphviz import Digraph\n",
    "\n",
    "def trace(root):\n",
    "  # builds a set of all nodes and edges in a graph\n",
    "  nodes, edges = set(), set()\n",
    "  def build(v):\n",
    "    if v not in nodes:\n",
    "      nodes.add(v)\n",
    "      for child in v._prev:\n",
    "        edges.add((child, v))\n",
    "        build(child)\n",
    "  build(root)\n",
    "  return nodes, edges\n",
    "\n",
    "def draw_dot(root):\n",
    "  dot = Digraph(format='svg', graph_attr={'rankdir': 'LR'}) # LR = left to right\n",
    "  \n",
    "  nodes, edges = trace(root)\n",
    "  for n in nodes:\n",
    "    uid = str(id(n))\n",
    "    # for any value in the graph, create a rectangular ('record') node for it\n",
    "    dot.node(name = uid, label = \"{ %s | data %.4f | grad %.4f }\" % (n.label, n.data, n.grad), shape='record')\n",
    "    if n._op:\n",
    "      # if this value is a result of some operation, create an op node for it\n",
    "      dot.node(name = uid + n._op, label = n._op)\n",
    "      # and connect this node to it\n",
    "      dot.edge(uid + n._op, uid)\n",
    "\n",
    "  for n1, n2 in edges:\n",
    "    # connect n1 to the op node of n2\n",
    "    dot.edge(str(id(n1)), str(id(n2)) + n2._op)\n",
    "\n",
    "  return dot\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 3.0.0 (20220226.1711)\n",
       " -->\n",
       "<!-- Pages: 1 -->\n",
       "<svg width=\"1157pt\" height=\"156pt\"\n",
       " viewBox=\"0.00 0.00 1157.00 156.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 152)\">\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-152 1153,-152 1153,4 -4,4\"/>\n",
       "<!-- 140306649871024 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>140306649871024</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"4.5,-111.5 4.5,-147.5 189.5,-147.5 189.5,-111.5 4.5,-111.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"16\" y=\"-125.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"27.5,-111.5 27.5,-147.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"67.5\" y=\"-125.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"107.5,-111.5 107.5,-147.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"148.5\" y=\"-125.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 6.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871264* -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>140306649871264*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"257\" cy=\"-101.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"257\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140306649871024&#45;&gt;140306649871264* -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>140306649871024&#45;&gt;140306649871264*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M189.91,-113.21C200.76,-111.29 211.28,-109.43 220.61,-107.77\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"221.37,-111.19 230.6,-106 220.15,-104.3 221.37,-111.19\"/>\n",
       "</g>\n",
       "<!-- 140306649871072 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>140306649871072</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"320,-28.5 320,-64.5 516,-64.5 516,-28.5 320,-28.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"331.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"343,-28.5 343,-64.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"386.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 10.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"430,-28.5 430,-64.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"473\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;2.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871744+ -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>140306649871744+</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"579\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"579\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
       "</g>\n",
       "<!-- 140306649871072&#45;&gt;140306649871744+ -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>140306649871072&#45;&gt;140306649871744+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M516.07,-62.98C525.42,-64.57 534.43,-66.1 542.55,-67.48\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"542.21,-70.97 552.65,-69.2 543.38,-64.07 542.21,-70.97\"/>\n",
       "</g>\n",
       "<!-- 140306649871120 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>140306649871120</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"0,-56.5 0,-92.5 194,-92.5 194,-56.5 0,-56.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"11.5\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"23,-56.5 23,-92.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"65.5\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"108,-56.5 108,-92.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"151\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;4.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871120&#45;&gt;140306649871264* -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>140306649871120&#45;&gt;140306649871264*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M194.01,-90.91C203.35,-92.5 212.37,-94.04 220.49,-95.43\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"220.16,-98.93 230.6,-97.16 221.34,-92.03 220.16,-98.93\"/>\n",
       "</g>\n",
       "<!-- 140306649871648 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>140306649871648</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"957,-27.5 957,-63.5 1149,-63.5 1149,-27.5 957,-27.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"969.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">L</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"982,-27.5 982,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1024.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;8.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"1067,-27.5 1067,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1108\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871648* -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>140306649871648*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"894\" cy=\"-45.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"894\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140306649871648*&#45;&gt;140306649871648 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>140306649871648*&#45;&gt;140306649871648</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M921.28,-45.5C928.78,-45.5 937.44,-45.5 946.67,-45.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"946.87,-49 956.87,-45.5 946.87,-42 946.87,-49\"/>\n",
       "</g>\n",
       "<!-- 140306649871744 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>140306649871744</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"642,-55.5 642,-91.5 831,-91.5 831,-55.5 642,-55.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"653.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"665,-55.5 665,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"705\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"745,-55.5 745,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"788\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;2.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871744&#45;&gt;140306649871648* -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>140306649871744&#45;&gt;140306649871648*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M831.1,-56.65C840.4,-54.97 849.38,-53.35 857.49,-51.89\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"858.37,-55.29 867.59,-50.07 857.13,-48.4 858.37,-55.29\"/>\n",
       "</g>\n",
       "<!-- 140306649871744+&#45;&gt;140306649871744 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>140306649871744+&#45;&gt;140306649871744</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M606.03,-73.5C613.66,-73.5 622.52,-73.5 631.94,-73.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"631.94,-77 641.94,-73.5 631.94,-70 631.94,-77\"/>\n",
       "</g>\n",
       "<!-- 140306649871264 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>140306649871264</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"321,-83.5 321,-119.5 515,-119.5 515,-83.5 321,-83.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"332.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">e</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"344,-83.5 344,-119.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"386.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"429,-83.5 429,-119.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"472\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;2.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871264&#45;&gt;140306649871744+ -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>140306649871264&#45;&gt;140306649871744+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M515.16,-84.57C524.82,-82.87 534.13,-81.23 542.49,-79.75\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"543.3,-83.17 552.54,-77.98 542.08,-76.27 543.3,-83.17\"/>\n",
       "</g>\n",
       "<!-- 140306649871264*&#45;&gt;140306649871264 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>140306649871264*&#45;&gt;140306649871264</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M284.26,-101.5C292.05,-101.5 301.1,-101.5 310.75,-101.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"310.99,-105 320.99,-101.5 310.99,-98 310.99,-105\"/>\n",
       "</g>\n",
       "<!-- 140306649871792 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>140306649871792</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"642.5,-0.5 642.5,-36.5 830.5,-36.5 830.5,-0.5 642.5,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"653\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">f</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"663.5,-0.5 663.5,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"706\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;2.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"748.5,-0.5 748.5,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"789.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 4.0000</text>\n",
       "</g>\n",
       "<!-- 140306649871792&#45;&gt;140306649871648* -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>140306649871792&#45;&gt;140306649871648*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M830.65,-34.67C840.2,-36.33 849.43,-37.93 857.72,-39.37\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"857.24,-42.84 867.69,-41.11 858.44,-35.95 857.24,-42.84\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7f9bb8244670>"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "draw_dot(L)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-7.286496\n"
     ]
    }
   ],
   "source": [
    "a.data += 0.01 * a.grad\n",
    "b.data += 0.01 * b.grad\n",
    "c.data += 0.01 * c.grad\n",
    "f.data += 0.01 * f.grad\n",
    "\n",
    "e = a * b\n",
    "d = e + c\n",
    "L = d * f\n",
    "\n",
    "print(L.data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-3.9999999999995595\n"
     ]
    }
   ],
   "source": [
    "def lol():\n",
    "  \n",
    "  h = 0.001\n",
    "  \n",
    "  a = Value(2.0, label='a')\n",
    "  b = Value(-3.0, label='b')\n",
    "  c = Value(10.0, label='c')\n",
    "  e = a*b; e.label = 'e'\n",
    "  d = e + c; d.label = 'd'\n",
    "  f = Value(-2.0, label='f')\n",
    "  L = d * f; L.label = 'L'\n",
    "  L1 = L.data\n",
    "  \n",
    "  a = Value(2.0, label='a')\n",
    "  b = Value(-3.0, label='b')\n",
    "  b.data += h\n",
    "  c = Value(10.0, label='c')\n",
    "  e = a*b; e.label = 'e'\n",
    "  d = e + c; d.label = 'd'\n",
    "  f = Value(-2.0, label='f')\n",
    "  L = d * f; L.label = 'L'\n",
    "  L2 = L.data\n",
    "  \n",
    "  print((L2 - L1)/h)\n",
    "  \n",
    "lol()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAjgklEQVR4nO3de3zU9Z3v8dcnE8IlQe6EcNGggIoXVAJUbWtAcVFrqbZrrbvWunU5rbrb9rTbutu92N2ze2y3Z3u2W7eUtq60i7LdVo5gUVBqKtYqFxUkXAwiQkgId0Ig5DLzOX/MBMcQIGQm85vJ7/18POYx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GfEdpr/o6SGQcC1wNzAj8Rm/mfiVLFlOawQiIiGnNQIRkZBTEIiIhJyCQEQk5BQEIiIhpyAQEQk5BYGISMgpCEREQu7/AyKbINjxDo2qAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(np.arange(-5,5,0.2), np.tanh(np.arange(-5,5,0.2))); plt.grid();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "metadata": {},
   "outputs": [],
   "source": [
    "# inputs x1,x2\n",
    "x1 = Value(2.0, label='x1')\n",
    "x2 = Value(0.0, label='x2')\n",
    "# weights w1,w2\n",
    "w1 = Value(-3.0, label='w1')\n",
    "w2 = Value(1.0, label='w2')\n",
    "# bias of the neuron\n",
    "b = Value(6.8813735870195432, label='b')\n",
    "# x1*w1 + x2*w2 + b\n",
    "x1w1 = x1*w1; x1w1.label = 'x1*w1'\n",
    "x2w2 = x2*w2; x2w2.label = 'x2*w2'\n",
    "x1w1x2w2 = x1w1 + x2w2; x1w1x2w2.label = 'x1*w1 + x2*w2'\n",
    "n = x1w1x2w2 + b; n.label = 'n'\n",
    "o = n.tanh(); o.label = 'o'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 244,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 3.0.0 (20220226.1711)\n",
       " -->\n",
       "<!-- Pages: 1 -->\n",
       "<svg width=\"1575pt\" height=\"210pt\"\n",
       " viewBox=\"0.00 0.00 1575.00 210.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 206)\">\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-206 1571,-206 1571,4 -4,4\"/>\n",
       "<!-- 140307056976896 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>140307056976896</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-165.5 2.5,-201.5 197.5,-201.5 197.5,-165.5 2.5,-165.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"19\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">w2</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"35.5,-165.5 35.5,-201.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"75.5\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 1.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"115.5,-165.5 115.5,-201.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"156.5\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
       "</g>\n",
       "<!-- 140307056976608* -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>140307056976608*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"263\" cy=\"-128.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"263\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140307056976896&#45;&gt;140307056976608* -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>140307056976896&#45;&gt;140307056976608*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M172.53,-165.44C181.84,-162.67 191.2,-159.67 200,-156.5 210.53,-152.71 221.75,-147.9 231.72,-143.33\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"233.25,-146.48 240.82,-139.07 230.28,-140.14 233.25,-146.48\"/>\n",
       "</g>\n",
       "<!-- 140307056979488 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>140307056979488</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"326,-55.5 326,-91.5 546,-91.5 546,-55.5 326,-55.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"352.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">x1*w1</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"379,-55.5 379,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"421.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"464,-55.5 464,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"505\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056977616+ -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>140307056977616+</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"609\" cy=\"-100.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"609\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
       "</g>\n",
       "<!-- 140307056979488&#45;&gt;140307056977616+ -->\n",
       "<g id=\"edge13\" class=\"edge\">\n",
       "<title>140307056979488&#45;&gt;140307056977616+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M546.27,-90.75C555.64,-92.23 564.6,-93.65 572.65,-94.92\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"572.23,-98.4 582.65,-96.5 573.32,-91.48 572.23,-98.4\"/>\n",
       "</g>\n",
       "<!-- 140307056979488* -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>140307056979488*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"263\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"263\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140307056979488*&#45;&gt;140307056979488 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>140307056979488*&#45;&gt;140307056979488</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.34,-73.5C297.77,-73.5 306.37,-73.5 315.6,-73.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"315.84,-77 325.84,-73.5 315.84,-70 315.84,-77\"/>\n",
       "</g>\n",
       "<!-- 140307056975936 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>140307056975936</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"2,-55.5 2,-91.5 198,-91.5 198,-55.5 2,-55.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"17\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">x1</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"32,-55.5 32,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"72\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"112,-55.5 112,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"155\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;1.5000</text>\n",
       "</g>\n",
       "<!-- 140307056975936&#45;&gt;140307056979488* -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>140307056975936&#45;&gt;140307056979488*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M198.37,-73.5C208.05,-73.5 217.4,-73.5 225.8,-73.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"225.91,-77 235.91,-73.5 225.91,-70 225.91,-77\"/>\n",
       "</g>\n",
       "<!-- 140307056975984 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>140307056975984</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"4,-110.5 4,-146.5 196,-146.5 196,-110.5 4,-110.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"19\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">x2</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"34,-110.5 34,-146.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"74\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"114,-110.5 114,-146.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"155\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056975984&#45;&gt;140307056976608* -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>140307056975984&#45;&gt;140307056976608*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M196.05,-128.5C206.52,-128.5 216.65,-128.5 225.71,-128.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"225.79,-132 235.79,-128.5 225.79,-125 225.79,-132\"/>\n",
       "</g>\n",
       "<!-- 140307056976512 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>140307056976512</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"1382,-54.5 1382,-90.5 1567,-90.5 1567,-54.5 1382,-54.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"1393.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">o</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"1405,-54.5 1405,-90.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1445\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.7071</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"1485,-54.5 1485,-90.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1526\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140307056976512tanh -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>140307056976512tanh</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"1319\" cy=\"-72.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"1319\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">tanh</text>\n",
       "</g>\n",
       "<!-- 140307056976512tanh&#45;&gt;140307056976512 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>140307056976512tanh&#45;&gt;140307056976512</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M1346.04,-72.5C1353.58,-72.5 1362.3,-72.5 1371.57,-72.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"1371.81,-76 1381.81,-72.5 1371.81,-69 1371.81,-76\"/>\n",
       "</g>\n",
       "<!-- 140307056978576 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>140307056978576</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"0,-0.5 0,-36.5 200,-36.5 200,-0.5 0,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"16.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">w1</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"33,-0.5 33,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"75.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"118,-0.5 118,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"159\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140307056978576&#45;&gt;140307056979488* -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>140307056978576&#45;&gt;140307056979488*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M169.28,-36.5C179.65,-39.61 190.16,-42.98 200,-46.5 210.28,-50.17 221.28,-54.74 231.11,-59.07\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"229.93,-62.37 240.48,-63.27 232.79,-55.99 229.93,-62.37\"/>\n",
       "</g>\n",
       "<!-- 140307056978624 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>140307056978624</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"716,-27.5 716,-63.5 901,-63.5 901,-27.5 716,-27.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"727.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"739,-27.5 739,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"779\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 6.8814</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"819,-27.5 819,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"860\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056976704+ -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>140307056976704+</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"1008\" cy=\"-72.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"1008\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
       "</g>\n",
       "<!-- 140307056978624&#45;&gt;140307056976704+ -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>140307056978624&#45;&gt;140307056976704+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M901.02,-58.01C926,-61.43 951.59,-64.93 971.37,-67.63\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"971.05,-71.12 981.43,-69.01 972,-64.18 971.05,-71.12\"/>\n",
       "</g>\n",
       "<!-- 140307056977616 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>140307056977616</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"672,-82.5 672,-118.5 945,-118.5 945,-82.5 672,-82.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"725\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">x1*w1 + x2*w2</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"778,-82.5 778,-118.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"820.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"863,-82.5 863,-118.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"904\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056977616&#45;&gt;140307056976704+ -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>140307056977616&#45;&gt;140307056976704+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M936.53,-82.49C949.09,-80.71 960.99,-79.02 971.3,-77.56\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"972.03,-80.99 981.44,-76.12 971.05,-74.06 972.03,-80.99\"/>\n",
       "</g>\n",
       "<!-- 140307056977616+&#45;&gt;140307056977616 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>140307056977616+&#45;&gt;140307056977616</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M636.23,-100.5C643.7,-100.5 652.41,-100.5 661.87,-100.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"661.98,-104 671.98,-100.5 661.98,-97 661.98,-104\"/>\n",
       "</g>\n",
       "<!-- 140307056976608 -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>140307056976608</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"328.5,-110.5 328.5,-146.5 543.5,-146.5 543.5,-110.5 328.5,-110.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"355\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">x2*w2</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"381.5,-110.5 381.5,-146.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"421.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"461.5,-110.5 461.5,-146.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"502.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056976608&#45;&gt;140307056977616+ -->\n",
       "<g id=\"edge14\" class=\"edge\">\n",
       "<title>140307056976608&#45;&gt;140307056977616+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M543.84,-111.01C554.01,-109.34 563.76,-107.74 572.44,-106.32\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"573.17,-109.75 582.47,-104.68 572.04,-102.84 573.17,-109.75\"/>\n",
       "</g>\n",
       "<!-- 140307056976608*&#45;&gt;140307056976608 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>140307056976608*&#45;&gt;140307056976608</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M290.34,-128.5C298.51,-128.5 308.08,-128.5 318.36,-128.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"318.39,-132 328.39,-128.5 318.39,-125 318.39,-132\"/>\n",
       "</g>\n",
       "<!-- 140307056976704 -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>140307056976704</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"1071,-54.5 1071,-90.5 1256,-90.5 1256,-54.5 1071,-54.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"1082.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">n</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"1094,-54.5 1094,-90.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1134\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.8814</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"1174,-54.5 1174,-90.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"1215\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.5000</text>\n",
       "</g>\n",
       "<!-- 140307056976704&#45;&gt;140307056976512tanh -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>140307056976704&#45;&gt;140307056976512tanh</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M1256.01,-72.5C1265.01,-72.5 1273.74,-72.5 1281.66,-72.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"1281.91,-76 1291.91,-72.5 1281.91,-69 1281.91,-76\"/>\n",
       "</g>\n",
       "<!-- 140307056976704+&#45;&gt;140307056976704 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>140307056976704+&#45;&gt;140307056976704</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M1035.04,-72.5C1042.58,-72.5 1051.3,-72.5 1060.57,-72.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"1060.81,-76 1070.81,-72.5 1060.81,-69 1060.81,-76\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7f9bc8477bb0>"
      ]
     },
     "execution_count": 244,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "draw_dot(o)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "metadata": {},
   "outputs": [],
   "source": [
    "o.backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 235,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Value(data=6.881373587019543),\n",
       " Value(data=2.0),\n",
       " Value(data=-3.0),\n",
       " Value(data=-6.0),\n",
       " Value(data=0.0),\n",
       " Value(data=1.0),\n",
       " Value(data=0.0),\n",
       " Value(data=-6.0),\n",
       " Value(data=0.8813735870195432),\n",
       " Value(data=0.7071067811865476)]"
      ]
     },
     "execution_count": 235,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "topo = []\n",
    "visited = set()\n",
    "def build_topo(v):\n",
    "  if v not in visited:\n",
    "    visited.add(v)\n",
    "    for child in v._prev:\n",
    "      build_topo(child)\n",
    "    topo.append(v)\n",
    "build_topo(o)\n",
    "topo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "metadata": {},
   "outputs": [],
   "source": [
    "o.grad = 1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [],
   "source": [
    "o._backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [],
   "source": [
    "n._backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [],
   "source": [
    "b._backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1w1x2w2._backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2w2._backward()\n",
    "x1w1._backward()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1.grad = w1.data * x1w1.grad\n",
    "w1.grad = x1.data * x1w1.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2.grad = w2.data * x2w2.grad\n",
    "w2.grad = x2.data * x2w2.grad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1w1.grad = 0.5\n",
    "x2w2.grad = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [],
   "source": [
    "x1w1x2w2.grad = 0.5\n",
    "b.grad = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [],
   "source": [
    "n.grad = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [],
   "source": [
    "o.grad = 1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4999999999999999"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1 - o.data**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# o = tanh(n)\n",
    "# do/dn = 1 - o**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 3.0.0 (20220226.1711)\n",
       " -->\n",
       "<!-- Pages: 1 -->\n",
       "<svg width=\"504pt\" height=\"45pt\"\n",
       " viewBox=\"0.00 0.00 504.00 45.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 41)\">\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-41 500,-41 500,4 -4,4\"/>\n",
       "<!-- 140307056784240 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>140307056784240</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"0,-0.5 0,-36.5 185,-36.5 185,-0.5 0,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"11.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"23,-0.5 23,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"63\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 3.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"103,-0.5 103,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"144\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 2.0000</text>\n",
       "</g>\n",
       "<!-- 140307056785008+ -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>140307056785008+</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"248\" cy=\"-18.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"248\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
       "</g>\n",
       "<!-- 140307056784240&#45;&gt;140307056785008+ -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>140307056784240&#45;&gt;140307056785008+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M185.01,-18.5C194.01,-18.5 202.74,-18.5 210.66,-18.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"210.91,-22 220.91,-18.5 210.91,-15 210.91,-22\"/>\n",
       "</g>\n",
       "<!-- 140307056785008 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>140307056785008</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"311,-0.5 311,-36.5 496,-36.5 496,-0.5 311,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"322.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"334,-0.5 334,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"374\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"414,-0.5 414,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"455\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140307056785008+&#45;&gt;140307056785008 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>140307056785008+&#45;&gt;140307056785008</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M275.04,-18.5C282.58,-18.5 291.3,-18.5 300.57,-18.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"300.81,-22 310.81,-18.5 300.81,-15 300.81,-22\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7f9b983636d0>"
      ]
     },
     "execution_count": 258,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = Value(3.0, label='a')\n",
    "b = a + a   ; b.label = 'b'\n",
    "b.backward()\n",
    "draw_dot(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 3.0.0 (20220226.1711)\n",
       " -->\n",
       "<!-- Pages: 1 -->\n",
       "<svg width=\"832pt\" height=\"100pt\"\n",
       " viewBox=\"0.00 0.00 832.00 100.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 96)\">\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-96 828,-96 828,4 -4,4\"/>\n",
       "<!-- 140306525506048 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>140306525506048</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"0,-55.5 0,-91.5 194,-91.5 194,-55.5 0,-55.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"11.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"23,-55.5 23,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"65.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;2.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"108,-55.5 108,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"151\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;3.0000</text>\n",
       "</g>\n",
       "<!-- 140307056785968+ -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>140307056785968+</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"257\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"257\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
       "</g>\n",
       "<!-- 140306525506048&#45;&gt;140307056785968+ -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>140306525506048&#45;&gt;140307056785968+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M194.01,-73.5C202.98,-73.5 211.65,-73.5 219.51,-73.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"219.7,-77 229.7,-73.5 219.7,-70 219.7,-77\"/>\n",
       "</g>\n",
       "<!-- 140306525506912* -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>140306525506912*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"257\" cy=\"-18.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"257\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140306525506048&#45;&gt;140306525506912* -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>140306525506048&#45;&gt;140306525506912*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M166.84,-55.49C176.04,-52.69 185.3,-49.67 194,-46.5 204.51,-42.67 215.73,-37.84 225.7,-33.28\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"227.23,-36.43 234.81,-29.02 224.27,-30.09 227.23,-36.43\"/>\n",
       "</g>\n",
       "<!-- 140307056785968 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>140307056785968</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"320.5,-55.5 320.5,-91.5 509.5,-91.5 509.5,-55.5 320.5,-55.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"332\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">e</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"343.5,-55.5 343.5,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"383.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 1.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"423.5,-55.5 423.5,-91.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"466.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;6.0000</text>\n",
       "</g>\n",
       "<!-- 140307056783712* -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>140307056783712*</title>\n",
       "<ellipse fill=\"none\" stroke=\"black\" cx=\"573\" cy=\"-45.5\" rx=\"27\" ry=\"18\"/>\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
       "</g>\n",
       "<!-- 140307056785968&#45;&gt;140307056783712* -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>140307056785968&#45;&gt;140307056783712*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M509.9,-56.65C519.42,-54.94 528.62,-53.29 536.89,-51.8\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"537.59,-55.23 546.81,-50.02 536.35,-48.34 537.59,-55.23\"/>\n",
       "</g>\n",
       "<!-- 140307056785968+&#45;&gt;140307056785968 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>140307056785968+&#45;&gt;140307056785968</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M284.11,-73.5C291.84,-73.5 300.8,-73.5 310.35,-73.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"310.48,-77 320.48,-73.5 310.48,-70 310.48,-77\"/>\n",
       "</g>\n",
       "<!-- 140306525506912 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>140306525506912</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"320,-0.5 320,-36.5 510,-36.5 510,-0.5 320,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"331.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"343,-0.5 343,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"385.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"428,-0.5 428,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"469\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140306525506912&#45;&gt;140307056783712* -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>140306525506912&#45;&gt;140307056783712*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M510.34,-34.83C519.62,-36.44 528.58,-37.99 536.66,-39.38\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"536.27,-42.87 546.72,-41.12 537.46,-35.97 536.27,-42.87\"/>\n",
       "</g>\n",
       "<!-- 140306525506912*&#45;&gt;140306525506912 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>140306525506912*&#45;&gt;140306525506912</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M284.11,-18.5C291.63,-18.5 300.32,-18.5 309.58,-18.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"309.81,-22 319.81,-18.5 309.81,-15 309.81,-22\"/>\n",
       "</g>\n",
       "<!-- 140307056783712 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>140307056783712</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"636,-27.5 636,-63.5 824,-63.5 824,-27.5 636,-27.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"646.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">f</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"657,-27.5 657,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"699.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"742,-27.5 742,-63.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"783\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n",
       "</g>\n",
       "<!-- 140307056783712*&#45;&gt;140307056783712 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>140307056783712*&#45;&gt;140307056783712</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M600.29,-45.5C607.78,-45.5 616.42,-45.5 625.6,-45.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"625.76,-49 635.76,-45.5 625.76,-42 625.76,-49\"/>\n",
       "</g>\n",
       "<!-- 140306525506432 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>140306525506432</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-0.5 2.5,-36.5 191.5,-36.5 191.5,-0.5 2.5,-0.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"14\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"25.5,-0.5 25.5,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"65.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 3.0000</text>\n",
       "<polyline fill=\"none\" stroke=\"black\" points=\"105.5,-0.5 105.5,-36.5 \"/>\n",
       "<text text-anchor=\"middle\" x=\"148.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;8.0000</text>\n",
       "</g>\n",
       "<!-- 140306525506432&#45;&gt;140307056785968+ -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>140306525506432&#45;&gt;140307056785968+</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M163.94,-36.53C174.08,-39.65 184.37,-43.01 194,-46.5 204.27,-50.22 215.26,-54.8 225.09,-59.12\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"223.91,-62.43 234.47,-63.32 226.77,-56.04 223.91,-62.43\"/>\n",
       "</g>\n",
       "<!-- 140306525506432&#45;&gt;140306525506912* -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>140306525506432&#45;&gt;140306525506912*</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M191.74,-18.5C201.55,-18.5 211.04,-18.5 219.59,-18.5\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"219.87,-22 229.87,-18.5 219.87,-15 219.87,-22\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7f9ba89cc880>"
      ]
     },
     "execution_count": 259,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = Value(-2.0, label='a')\n",
    "b = Value(3.0, label='b')\n",
    "d = a * b    ; d.label = 'd'\n",
    "e = a + b    ; e.label = 'e'\n",
    "f = d * e    ; f.label = 'f'\n",
    "\n",
    "f.backward()\n",
    "\n",
    "draw_dot(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
